<?php
class ExtLb_Controller_Plugin_AccessCheck extends Zend_Controller_Plugin_Abstract {
	
	public function preDispatch(Zend_Controller_Request_Abstract $request){
		$auth = Zend_Auth::getInstance();
		$acl = Zend_Registry::get('acl');
		
		if($auth->hasIdentity()){
			$storage = $auth->getStorage()->read();
			$controllerName = $this->_request->getControllerName();

			if($request->getModuleName()=="admin"){
				$zVHelper = new Zend_Controller_Action_Helper_FlashMessenger();
				if(!$acl->isAllowed($storage->quyen, $controllerName,$request->getActionName())){
					
//					$zVHelper->addMessage("<center><font size='6'>Bạn không có quyền sử dụng chức năng này </font></center>","warm_ms");
					
					$request->setModuleName('admin')
							->setControllerName('index')
							->setActionName('index');
	
				}else{
//					$zVHelper->clearMessages();
				}
			}
		}else{
			if ($request->getModuleName() =="admin"){
				$request->setModuleName('front')
							->setControllerName('login')
							->setActionName('index');
			}
		}
	}
}